package com.ajk.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ajk.server.dao.ChatThreadMapper;
import com.ajk.server.model.ChatThread;
import com.ajk.server.model.query.ChatThreadQuery;
import com.ajk.server.service.ChatThreadService;

/**
 * 聊天组表  <br>
 * t_chat_thread <br>
 * v1.0 2016-05-01
 */
 @Service
 public class ChatThreadServiceImpl implements ChatThreadService {
	
	private static final Logger logger = LoggerFactory.getLogger(ChatThreadServiceImpl.class);
	
	@Autowired
	private ChatThreadMapper chatThreadMapper;
	
	/**
 	*根据ID删除 聊天组表
 	*/
 	@Override
 	public Integer deleteChatThreadById(Integer id){
 		return chatThreadMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 聊天组表
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertChatThread(List<? extends ChatThread> chatThreads){
		Integer count = chatThreadMapper.batchInsert(chatThreads);
		return count;
 	}
 	/**
 	*新增 聊天组表
 	*/
 	@Override
 	@Transactional
 	public Integer insertChatThread(ChatThread domain){
		Integer id = chatThreadMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 聊天组表
 	*/
 	@Override
 	@Transactional
 	public Integer updateChatThread(ChatThread domain){
		Integer count = chatThreadMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 聊天组表
 	*/
 	public ChatThread findChatThreadById(Integer id){
 		ChatThread result = chatThreadMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 聊天组表
 	*/
	public List<ChatThread> findChatThreadByQuery(ChatThreadQuery query){
		query.dealWith();
		List<ChatThread> result = chatThreadMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (ChatThread chatThread : result) {
				chatThread.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countChatThreadByQuery(ChatThreadQuery query){
 		query.dealWith();
 		Integer result = chatThreadMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<ChatThread> findChatThreadByIds(List<Integer> ids){
 		List<ChatThread> result = chatThreadMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (ChatThread chatThread : result) {
				chatThread.dealWith();
			}
		}
		return result;
 	}
 	
}	